// pages/find/find.js
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },
  options: {
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
   id:'',
    bgimg1: app.globalData.bgimg,
    haveImg: app.globalData.haveImg

  },
  attached()
  {
    var that=this
    wx.request({
      url: 'https://sdu-miniprogram.cn:8888/api/miniprogram/chatInfo/getChatRoomRank',
      method:'POST',
      data:{
        token:app.globalData.userInfo.token,
        
      },
      success:function(e)
      {
        console.log(e.data.list)
        // that.setData({
        //   list: e.data.list
        // })
        //处理一下好看一点时间
        var list= e.data.list
        console.log(list)
        for(var i=0;i<e.data.list.length;i++)
        {
          list[i].createTime=list[i].createTime.substring(0,10)
          list[i].count = i+1
          // console.log(temp)
          // list.push(temp)
        }
        console.log(list)
        that.setData({
          list: list,
          bgimg1: app.globalData.bgimg,
          haveImg: app.globalData.haveImg
        })
      }
    })

  },

  /**
   * 组件的方法列表
   */
  methods: {
    apply:function(e)
    {
      var that = this
      var msg = "请问你要加入这个群聊吗?"
      that.data.id = e.currentTarget.dataset.id * 1
      that.setData({
        type: 'apply',
        msg: msg
      })
    },
    AddChat:function(e)
    {
      console.log(e)
      var that =this
      that.setData({
        type: '',
      })
      //共用一个防止死循环
      if(e.currentTarget.dataset.type=='apply')
      {
      console.log(e)
      wx.request({
      url: 'https://sdu-miniprogram.cn:8888/api/miniprogram/chatInfo/joinChatRoom',
      method: 'POST',
      data:
      {
        token: app.globalData.userInfo.token,
        roomId: that.data.id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          type: 'notice',
          msg: res.data.errmsg
        })
      }
    })
    }
      
    },
    hideModal:function(e)
    {
      this.setData({
        type: '',
      })
    }

  }
})
